package com.oedtech.esl.repository.sys;

import com.oedtech.esl.model.sys.Role;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface RoleDao extends JpaRepository<Role,Long>,JpaSpecificationExecutor<Role>{
    @Query(value = "select r.* " +
            "from " +
            "sys_user u join sys_user_role ur on u.id=ur.user_id " +
            "join sys_role r on r.id=ur.role_id  " +
            "where u.username=?1",nativeQuery = true)
    List<Role>findRole(String username);

    @Query(value = "select count(id) from sys_role where role_code=?1")
    Integer findCountByRoleCode(String roleCode);

    @Query(value = "select * from sys_role where role_code <>'ROLE_SUPPERADMIN'",nativeQuery = true)
    List<Role>findAllNotSupper();
}
